package com.huang.community.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
/**
 * Rabbitmq队列声明
 * @author TianTian
 * @date 2022/4/25 21:27
 */
@Configuration
public class RabbitMqQueueConfig {
    //交换机名字
    public static final String X_EXCHANGE = "X";
    //队列A 处理follow消息
    public static final String QUEUE_A = "QA";
    //队列B 处理Comment消息
    public static final String QUEUE_B = "QB";
    //队列C 处理like消息
    public static final String QUEUE_C = "QC";
    //队列D 处理publish消息
    public static final String QUEUE_D = "QD";
    //队列D 处理delet消息
    public static final String QUEUE_E = "QE";



    // 声明 xExchange
    @Bean("xExchange")
    public DirectExchange xExchange(){
        return new DirectExchange(X_EXCHANGE);
    }

    @Bean("queueA")
    public Queue queueA(){
        return QueueBuilder.durable(QUEUE_A).build();
    }
    // 声明队列 A 绑定 X 交换机
    @Bean
    public Binding queueaBindingX(@Qualifier("queueA") Queue queueA,
                                  @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueA).to(xExchange).with("follow");
    }
    //声明队列 B
    @Bean("queueB")
    public Queue queueB(){

        return QueueBuilder.durable(QUEUE_B).build();
    }
    //声明队列 B 绑定 X 交换机
    @Bean
    public Binding queuebBindingX(@Qualifier("queueB") Queue queueB,
                                  @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueB).to(xExchange).with("comment");
    }
    //声明队列 C
    @Bean("queueC")
    public Queue queueC(){
        return QueueBuilder.durable(QUEUE_C).build();
    }
    //声明队列 B 绑定 X 交换机
    @Bean
    public Binding queuecBindingX(@Qualifier("queueC") Queue queueC,
                                  @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueC).to(xExchange).with("like");
    }
    //声明队列 D
    @Bean("queueD")
    public Queue queueD(){
        return QueueBuilder.durable(QUEUE_D).build();
    }
    //声明队列 D 绑定关系
    @Bean
    public Binding deadLetterBindingQD(@Qualifier("queueD") Queue queueD,
                                        @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueD).to(xExchange).with("publish");
    }
    //声明队列 E
    @Bean("queueE")
    public Queue queueE(){
        return QueueBuilder.durable(QUEUE_E).build();
    }
    //声明队列 E 绑定关系
    @Bean
    public Binding deadLetterBindingQE(@Qualifier("queueE") Queue queueD,
                                        @Qualifier("xExchange") DirectExchange xExchange){
        return BindingBuilder.bind(queueD).to(xExchange).with("delete");
    }

}
